from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-04-16 14:10:50.480932
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 16, Apr, 2021
Time: 14:10:54
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.5657
Nobs: 263.000 HQIC: -48.2968
Log likelihood: 3147.01 FPE: 6.48246e-22
AIC: -48.7881 Det(Omega_mle): 4.63317e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.439244 0.124724 3.522 0.000
L1.Burgenland 0.080168 0.061495 1.304 0.192
L1.Kärnten -0.222556 0.054009 -4.121 0.000
L1.Niederösterreich 0.078043 0.134319 0.581 0.561
L1.Oberösterreich 0.210378 0.126824 1.659 0.097
L1.Salzburg 0.271451 0.070146 3.870 0.000
L1.Steiermark 0.124640 0.089627 1.391 0.164
L1.Tirol 0.120213 0.061504 1.955 0.051
L1.Vorarlberg -0.035493 0.056614 -0.627 0.531
L1.Wien -0.055327 0.115125 -0.481 0.631
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.480366 0.145396 3.304 0.001
L1.Burgenland 0.000322 0.071687 0.004 0.996
L1.Kärnten 0.329154 0.062960 5.228 0.000
L1.Niederösterreich 0.075819 0.156581 0.484 0.628
L1.Oberösterreich -0.068225 0.147845 -0.461 0.644
L1.Salzburg 0.223620 0.081772 2.735 0.006
L1.Steiermark 0.109142 0.104482 1.045 0.296
L1.Tirol 0.141600 0.071698 1.975 0.048
L1.Vorarlberg 0.154511 0.065997 2.341 0.019
L1.Wien -0.434221 0.134206 -3.235 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.285770 0.062139 4.599 0.000
L1.Burgenland 0.090436 0.030637 2.952 0.003
L1.Kärnten -0.018701 0.026908 -0.695 0.487
L1.Niederösterreich 0.053826 0.066919 0.804 0.421
L1.Oberösterreich 0.275546 0.063185 4.361 0.000
L1.Salzburg 0.025845 0.034947 0.740 0.460
L1.Steiermark 0.011298 0.044653 0.253 0.800
L1.Tirol 0.072266 0.030642 2.358 0.018
L1.Vorarlberg 0.081828 0.028206 2.901 0.004
L1.Wien 0.126139 0.057356 2.199 0.028
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.215288 0.060956 3.532 0.000
L1.Burgenland 0.022088 0.030054 0.735 0.462
L1.Kärnten 0.008444 0.026395 0.320 0.749
L1.Niederösterreich 0.051598 0.065645 0.786 0.432
L1.Oberösterreich 0.399308 0.061982 6.442 0.000
L1.Salzburg 0.083425 0.034282 2.433 0.015
L1.Steiermark 0.128724 0.043803 2.939 0.003
L1.Tirol 0.049743 0.030058 1.655 0.098
L1.Vorarlberg 0.084244 0.027669 3.045 0.002
L1.Wien -0.042830 0.056264 -0.761 0.447
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.497667 0.118893 4.186 0.000
L1.Burgenland 0.092294 0.058620 1.574 0.115
L1.Kärnten 0.011071 0.051484 0.215 0.830
L1.Niederösterreich 0.002268 0.128040 0.018 0.986
L1.Oberösterreich 0.127956 0.120896 1.058 0.290
L1.Salzburg 0.059860 0.066867 0.895 0.371
L1.Steiermark 0.066905 0.085437 0.783 0.434
L1.Tirol 0.212590 0.058629 3.626 0.000
L1.Vorarlberg 0.031266 0.053967 0.579 0.562
L1.Wien -0.094430 0.109743 -0.860 0.390
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.192617 0.093985 2.049 0.040
L1.Burgenland -0.015633 0.046339 -0.337 0.736
L1.Kärnten -0.008329 0.040698 -0.205 0.838
L1.Niederösterreich -0.005453 0.101216 -0.054 0.957
L1.Oberösterreich 0.403183 0.095568 4.219 0.000
L1.Salzburg 0.015870 0.052858 0.300 0.764
L1.Steiermark -0.018606 0.067538 -0.275 0.783
L1.Tirol 0.160181 0.046346 3.456 0.001
L1.Vorarlberg 0.053474 0.042661 1.253 0.210
L1.Wien 0.228070 0.086752 2.629 0.009
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.236594 0.114409 2.068 0.039
L1.Burgenland 0.018536 0.056409 0.329 0.742
L1.Kärnten -0.069805 0.049542 -1.409 0.159
L1.Niederösterreich -0.074336 0.123211 -0.603 0.546
L1.Oberösterreich 0.018826 0.116336 0.162 0.871
L1.Salzburg 0.083833 0.064345 1.303 0.193
L1.Steiermark 0.336294 0.082215 4.090 0.000
L1.Tirol 0.461799 0.056418 8.185 0.000
L1.Vorarlberg 0.147624 0.051932 2.843 0.004
L1.Wien -0.155121 0.105604 -1.469 0.142
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183028 0.136538 1.340 0.180
L1.Burgenland 0.039867 0.067320 0.592 0.554
L1.Kärnten -0.075045 0.059125 -1.269 0.204
L1.Niederösterreich 0.131142 0.147042 0.892 0.372
L1.Oberösterreich 0.017763 0.138838 0.128 0.898
L1.Salzburg 0.200257 0.076791 2.608 0.009
L1.Steiermark 0.117267 0.098117 1.195 0.232
L1.Tirol 0.057934 0.067330 0.860 0.390
L1.Vorarlberg 0.103052 0.061977 1.663 0.096
L1.Wien 0.231064 0.126030 1.833 0.067
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.560950 0.074125 7.568 0.000
L1.Burgenland -0.025332 0.036547 -0.693 0.488
L1.Kärnten -0.023165 0.032098 -0.722 0.470
L1.Niederösterreich 0.053481 0.079827 0.670 0.503
L1.Oberösterreich 0.309493 0.075374 4.106 0.000
L1.Salzburg 0.021712 0.041689 0.521 0.603
L1.Steiermark -0.035340 0.053266 -0.663 0.507
L1.Tirol 0.085436 0.036553 2.337 0.019
L1.Vorarlberg 0.111127 0.033646 3.303 0.001
L1.Wien -0.052170 0.068420 -0.762 0.446
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.148538 0.080384 0.165882 0.223244 0.074781 0.083161 0.013596 0.153065
Kärnten 0.148538 1.000000 0.038112 0.205570 0.179643 -0.064190 0.165344 0.026779 0.302007
Niederösterreich 0.080384 0.038112 1.000000 0.238836 0.078335 0.320001 0.142111 0.027904 0.292548
Oberösterreich 0.165882 0.205570 0.238836 1.000000 0.301773 0.264075 0.090463 0.060199 0.129950
Salzburg 0.223244 0.179643 0.078335 0.301773 1.000000 0.152437 0.054018 0.088508 0.008298
Steiermark 0.074781 -0.064190 0.320001 0.264075 0.152437 1.000000 0.102257 0.095318 -0.107556
Tirol 0.083161 0.165344 0.142111 0.090463 0.054018 0.102257 1.000000 0.161507 0.146601
Vorarlberg 0.013596 0.026779 0.027904 0.060199 0.088508 0.095318 0.161507 1.000000 -0.010190
Wien 0.153065 0.302007 0.292548 0.129950 0.008298 -0.107556 0.146601 -0.010190 1.000000